<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

// 应用公共文件
use think\Db;
function get_cate_data($pid = 0,&$dataAll = array()){
	$data = Db::table('lsq_product_category')->where('category_pid',$pid)->select();	
	if($data){
		foreach($data as $val){
			$dataAll[] = $val;
			get_cate_data($val['category_id'],$dataAll);
		}
	}
	return $dataAll;
}
function get_cate_tree($pid = 0,$data = array()){
	$assoc = Db::table('lsq_product_category')->where('category_pid',$pid)->select();
	foreach($assoc as $val){
		$val['child'] = get_cate_tree($val['category_id']);
		$data[] = $val;
	}
	return $data;
}
function get_cate_tree_html($pid = 0,$data = ''){
	$assoc = Db::table('lsq_product_category')->where('category_pid',$pid)->select();
	foreach($assoc as $val){
		$spl = arrow($val['category_grade']);
		if($val['category_pid'] == 0){
			$data .= "<option value=\"{$val['category_id']}\">{$val['category_name']}</option>";
		}else{
			$data .= "<option value=\"{$val['category_id']}\">|".$spl."{$val['category_name']}</option>";
		}
		$data .= get_cate_tree_html($val['category_id']);
	}
	return $data;
}

function arrow($num){
	$spl = '';
	for($i = 0; $i < $num - 1; $i++){
		$spl .= "---";
	}
	return $spl;
}

function get_cate($id,$pid=0,&$dataAll = array()){
	$data = Db::table('lsq_product_category')->where('category_pid',$id)->select();	
	if($data){
		foreach($data as $val){
			$dataAll[] = $val;
			get_cate($val['category_id'],$dataAll);
		}
	}
	return $dataAll;
	}




